import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-08-31
 * Time: 10:28
 */
class Solution1 {
    // 解法二 哈希表
    public int[] twoSum(int[] nums, int target) {
        int n = nums.length;

        //放的是nums[i],i绑定
        Map<Integer,Integer> hash = new HashMap<>();

        for(int i = 0; i < n; i++) {
            int x = target-nums[i];
            if(hash.containsKey(x)) {
                return new int[]{i,hash.get(x)};
            }
            hash.put(nums[i],i);
        }
        return null;
    }
}
